<?php 
	include("session.php"); 
	include("util/message.php"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>

.carousel_html {
  	width:976px;
  	height:190px;
  	min-width:976px;
  	min-height:190px;
  	max-width:976px;
  	max-height:190px;
  	overflow:hidden;
  	display:block;
}
.tabs li a { margin: 1px; border: none !important; }
</style>

<title>Miti</title>
<?php 
    include("import.php");
    include("./service/productService.php");
    include("./service/categoryService.php");
    include("./service/commentService.php");
    include("./service/userService.php");
    include("./service/branchService.php");
    include("./service/specialProductService.php");
	include("./service/bannerService.php");
	include_once("./util/message.php");
?>
</head>

<body>
<!-- Wrapper -->
<div class="wrapper">
    <!-- Floating banner -->
    <?php include("floating-banner.php");?>
    <!-- End of floating banner -->
    
	<!-- Top banner -->
	<?php include("header.php");?>
    <!-- End of top banner -->
    
    <!-- Navigator -->
	<?php include("navigator.php");?>
    <!-- End of navigator -->
    
    <!-- Menu, newsletter and search -->
    <?php include("menu.php");?>
    <!-- End of menu, newsletter and search -->
    
    <!-- Content -->
    <div class="wrapper-content">
       	<!-- Special product -->
        <div class="upper-banner">
            <?php
            $eventBanner = getActiveEventBanner(); 
			if(isset($eventBanner["BANNER_EVE_ID"])){
			?>
		        <a target="_blank" href="./news-detail.php?a=<?php echo $eventBanner["BANNER_EVE_ID"]; ?>">
                    <img style="width: 241px; height: 496px;" src="<?php echo $eventBanner["BANNER_IMG_PATH"]; ?>"/>
                </a>
            <?php
			}
			?>
        </div>
        <!--
        <div class="special-product-wrapper">
            <?php
                /*
            ?>
        	<div class="title">Đấu giá trực tuyến</div>
            <div class="spiral-arrow">360<sup>o</sup></div>
            <div id="360"></div>
            <div class="price">
            	<?php
                        $specialProduct = findActiveSpecialProduct();
                ?>
                <a href="product-detail.php?product=<?php echo $specialProduct["SPRO_PRO_ID"]=="" ? 0 : $specialProduct["SPRO_PRO_ID"];?>">
                    <div class="vn-currency"><?php echo number_format(getDiscountedAndOptionalPriceOfProduct($specialProduct["SPRO_PRO_ID"]));?></div>
                    <div>Chi tiết</div>
                </a>
            </div>
            <div class="name"><div><?php echo $specialProduct["NAME"];?></div></div>
            <?
                */
            ?>
        </div>
        -->
        <!-- End of special product -->
        
        <!-- New product -->
    	<div class="new-product-wrapper">
        	<div id="new-product-slider" class="carousel slide" style="z-index: 99;">
                <!-- Wrapper for slides -->
                <div class="carousel-inner">
                    <?php
						$newProductBanners = findAllNewProductBanners(2);
						$count = 0;
						while($row = mysql_fetch_array($newProductBanners)){
							$productData = preg_split("/,/", $row["PRODUCT"]);
							if($count == 0) echo "<div style='cursor:pointer;' class='item active' onclick='window.location.href = \"product-detail.php?product=".$productData[0]."\";'><img src='".$row["BANNER_IMG_PATH"]."'></div>";
							else echo "<div class='item'><img src='".$row["BANNER_IMG_PATH"]."'></div>";
							$count++;
						}
                    ?>
                </div>
                <a class="new-product-left" href="#new-product-slider" data-slide="prev"></a>
                <a class="new-product-right" href="#new-product-slider" data-slide="next"></a>
            </div>
        </div>
    	<!-- End of new product -->   
        
        <div class="clear"></div>
        
        <!-- Middle banner -->
         <?php
			$centerBanner = getActiveCenterBanner(); 
			if(isset($centerBanner["BANNER_EVE_ID"])){
		?>
        <div class="middle-banner-wrapper">
           
            <a target="_blank" href="./news-detail.php?a=<?php echo $centerBanner["BANNER_EVE_ID"]; ?>">
                <img style="width: 978px; height: 90px;" src="<?php echo $centerBanner["BANNER_IMG_PATH"]; ?>"/>
            </a>
        </div>
        <?php
			}
        ?>
        <!-- End of middle banner -->
        
        <!-- Index product wrapper -->
        <div class="index-product-wrapper">
        </div>
        <!-- End of index product wrapper -->
		
        <div class="clear"></div>
		
        <!-- Paging -->
        <?php
            $latestProducts = getLatestProduct(1,32);
            $numbOfLatestProduct = mysql_num_rows($latestProducts);
        ?>
        <div id="example_paging" class="paging"></div>
        <script type='text/javascript'>
            var options = {
                alignment:"right",
                currentPage: 1,
                totalPages: <?php echo ceil($numbOfLatestProduct / 16); ?>,
                onPageClicked: function(e,originalEvent,type,page){
                    $.ajax({
                        type: "GET",
                        url: "./action/ajax/getLatestProduct.php",
                        data: { p: page, user:userid }
                    }).done(function( data ) {
                        $(".index-product-wrapper").empty();
                        $(".index-product-wrapper").html(data);
                        try{
                            p = p;    
                        }catch(err){
                            
                        }
                    });
                }
            }
    
            $('#example_paging').bootstrapPaginator(options);
        </script>
        <!-- End of Paging -->
        
        <div class="clear"></div>
        <!-- Best seller -->
        <div class="best-seller-wrapper">
        	<div class="best-seller-title">BÁN CHẠY NHẤT HÔM NAY</div>
            <div class="best-seller-slider-wrapper">
                <div id="carousel-example-generic" class="carousel slide" style="z-index: 9;">
					<!-- Indicators -->
					<!-- Wrapper for slides -->
					<div class="carousel-inner">
    					<?php
                            $bestSellers = getBestSellerProduct();
                            $runner = 1;
                            $max = count($bestSellers);
                            foreach ($bestSellers as $item) {
                                if($runner==1 || $runner==8 || $runner==15){
                                    echo "<div class='item ";
                                        if($runner==1){
                                            echo "active";
                                        }
                                    echo "'>";
                                    echo "<div class='carousel_html'>";      
                                }
                        ?>
                                                                                            
                                    <div class="best-seller" onclick="submitAction('product-detail.php?product=<?php echo $item["PRO_ID"];?>');">
                                        <?php
                                            $images = findImagesOfProduct($item["PRO_ID"]);
                                            $firstImg = mysql_fetch_array($images);
                                        ?>
                                        <img id="<?php echo $item["PRO_ID"];?>" src="<?php echo "./image/product/".$item["PRO_ID"]."/thumbnail/".$firstImg["IMG_PATH"]; ?>"/>
    									<div class="best-seller-name"><?php echo $item["PRO_NAME"]; ?></div>
    									<div class="best-seller-price vn-currency"><?php echo number_format($item["PRO_PRICE"]); ?></div>
    								</div>                               
                        <?php
                                if($runner==7 || $runner==14 || $runner==21){
                                    echo "</div></div>";    
                                }else if($max == $runner){
                                    echo "</div></div>";
                                }
                                $runner++;
                            }
                        ?>
                            
                  </div>
                  <!-- Controls -->
                  <a class="left" href="#carousel-example-generic" data-slide="prev">
                    <span class="icon-prev"></span>
                  </a>
                  <a class="right" href="#carousel-example-generic" data-slide="next">
                    <span class="icon-next"></span>
                  </a>
                </div>
            </div>
        </div>
        <!-- End of best seller -->
        
        <div class="clear"></div>
        
        <!-- Branch, statistics and facebook like -->
        <div class="pre-footer-wrapper">
        	<!-- Branch -->
        	<div class="branch-wrapper">
            	<div class="branch-wrapper-title">ĐỊA CHỈ CHI NHÁNH</div>
                <div class="tabs" id="branches" style="overflow: hidden;">
                    <?php
                        $branches = getAllBranch();
                        $strTabContent = "";
                        if(mysql_num_rows($branches) > 0){
                    ?>
                	<ul>
                        <?php
                            while($branch = mysql_fetch_array($branches)){
                        ?>
                            <li><a href="#tabs<?php echo $branch["BRA_ID"]; ?>"><?php echo $branch["BRA_NAME"]; ?></a></li>
                        <?php
                            $strTabContent .= "<div  style='min-height:128px;overflow:auto;' id='tabs".$branch["BRA_ID"]."'>".$branch["BRA_ADDRESS"]."</div>";
                            }
                        ?>
                    </ul>
                        <?php
                            echo $strTabContent;
                        ?>
                    <?php
                    }
                    ?>
                    
                </div>
            </div>
            <!-- End of branch -->
            
            <!-- Statistics -->
            <div class="access-statistics-wrapper">
            	<div class="statistics-title">
                	<span>THỐNG KÊ TRUY CẬP</span>
                    <?php                    
                        include_once("counter.php");
                    ?>
                </div>
            </div>
            <!-- End of statistics -->
            
            <!-- Facebook like -->
			<div class="facebook-like-wrapper">
            	<div id="fb-root"></div>
                <script>
					(function(d, s, id) {
						var js, fjs = d.getElementsByTagName(s)[0];
						if (d.getElementById(id)) return;
						js = d.createElement(s); js.id = id;
						js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
						fjs.parentNode.insertBefore(js, fjs);
					}(document, 'script', 'facebook-jssdk'));
                </script>
                <div class="fb-like-box" data-href="https://www.facebook.com/pages/Th%E1%BA%BF-Gi%E1%BB%9Bi-T%C3%BAi-C%E1%BA%B7p-V%C4%83n-Ph%C3%B2ng/719426121411859?ref=hl" data-width="260" data-height="211" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="false" data-show-border="true"></div>
            </div>            <!-- End of facebook like -->
        </div>
        <!-- End branch, statistics and facebook like -->
        
        <!-- Live support -->
        <?php include("live-support.php");?>
        <!-- End of live support -->
        
        <div class="clear"></div>
        <!-- Footer -->
        <?php include("footer.php");?>
        <!-- End of footer -->
    </div>
    <!-- End of content -->
</div>
<!-- End of wrapper -->
<!--
<div class="live-support-wrapper">
    <a href="./mibew/client.php?locale=vi&amp;style=original" target="_blank" onclick="if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 &amp;&amp; window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open(&#039;./mibew/client.php?locale=en&amp;style=original&amp;url=&#039;+escape(document.location.href)+&#039;&amp;referrer=&#039;+escape(document.referrer), 'mibew', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">
    	<div class="chat-icon" style="background-size: contain;">
            <div style="padding: 10px 10px 10px 10px; font-size: 11px;">
                <h4>Bạn cần hỗ trợ</h4>
                Bấm vào đây để chat với chúng tôi
            </div>
        </div>
        <div style="clear: both;"></div>    
        <img src="./mibew/b.php?i=simple&amp;amp;lang=en" border="0" width="150" height="55" alt=""/>
    </a>
</div>
<div class="arrow-up-icon"></div>
-->
<script>
    $(document).ready(function(){
        $('.carousel').carousel({ interval: 4000, animation: { duration: 2500 } });
        $.ajax({
            type: "GET",
            url: "./action/ajax/getLatestProduct.php",
            data: { p: 1,user:userid }
        }).done(function( data ) {
            $(".index-product-wrapper").html(data);
            $(".product-price").each(function(){
                var price = $(this).html();
                $(this).html(formatCurrency(price,2));
            }); 
            try{
                p = 1;    
            }catch(err){
                
            }
        });
		
		var frames = [
            <?php
                $specialImages = findImagesOfActiveSpecialProduct();
                $numOfImage = mysql_num_rows($specialImages) - 1;
                $count = 0;
                
                while($row = mysql_fetch_array($specialImages)){
                    if($count == $numOfImage) echo "'image/product/special/".$row["SPRO_ID"]."/thumbnail/".$row["IMG_PATH"]."'";
                    else echo "'image/product/special/".$row["SPRO_ID"]."/thumbnail/".$row["IMG_PATH"]."',";
                    $count++;
                }
            ?>    
        ];
		
		$("#360").spritespin({
			width     : 263,
			height    : 356,
			frames    : frames.length,
			behavior  : "drag",
			module    : "360",
			sense     : -1,
			source    : frames,
			animate   : false,
			loop      : false,
			frameWrap : true,
			frameTime : 60,
			enableCanvas : false
      	});
		$("#360").css("margin-top", "45px").css("margin-left", "4px");
		//$(".spritespin-stage img").css("width", "263");
		//$(".spritespin-stage img").css("height", "356");
    });
	
	function addToCart(proId){
		$.ajax({
			type: "POST",
			url: "action/ajax/addProductToCartProcess.php",
			data: { "proId" : proId, "quantity" : 1 , "optionItem" : null},
			success: function(data){
				$("#numPro").html("(" + data + ")");
			}
		});
	}
	
	$(window).bind("load", function() {
		$(".mCSB_dragger").css("right", "3px");
		$(".mCSB_dragger_bar").css("width", "8px");
	});

</script>
</body>
</html>
